package com.example.demo.interceptor;

import com.example.demo.service.CacheService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Author:lgl
 * @Description:
 * @Date:Created in 2017/12/5.
 */
@Aspect
@Component
@Order(-1)
public class CacheAspect {

    @Autowired
    private CacheService cacheService;

    @Pointcut("execution(* com.example.demo.service.impl..*(..))")
    public void cache(){}

    @Before("cache()")
    public void doBefore(JoinPoint joinPoint)throws Throwable{
        String methodName = joinPoint.getSignature().getName();
        if(methodName.equals("selectVideoId")){
            cacheService.selectDB(4);
        }else if(methodName.equals("saveRank")||methodName.equals("selectRank")){
            cacheService.selectDB(3);
        }else if(methodName.equals("selectDB")){

        }else{
            cacheService.selectDB(0);
        }
    }

}
